package com.pocketsweet.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.avos.avoscloud.AVAnalytics;
import com.avos.avoscloud.AVException;
import com.avos.avoscloud.SaveCallback;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.pocketsweet.R;
import com.pocketsweet.chat.ui.activity.BaseActivity;
import com.pocketsweet.model.MLUser;
import com.pocketsweet.service.UserService;
import com.pocketsweet.ui.uilib.ActionSheetDialog;
import com.pocketsweet.ui.uilib.ActionSheetDialog.OnSheetItemClickListener;
import com.pocketsweet.ui.uilib.ActionSheetDialog.SheetItemColor;
import com.pocketsweet.utils.ToolKits;

@ContentView(R.layout.activity_privilege)
public class Privilege extends BaseActivity {

	@ViewInject(R.id.imgTaskPic)
	private ImageView imgTaskPic;

	@ViewInject(R.id.relSetTariff)
	private RelativeLayout relSetTariff;

	@ViewInject(R.id.relHowToBe)
	private RelativeLayout relHowToBe;

	@ViewInject(R.id.tvMyTariff)
	private TextView tvMyTariff;

	private MLUser mlUser;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ViewUtils.inject(this);
		mlUser = UserService.getCurrentUser();
		if (mlUser.getPrice() != 0.0) {
			tvMyTariff.setText(String.valueOf(mlUser.getPrice()) + "元／分钟");
		} else {
			tvMyTariff.setText("未设置");
		}
	}

	public void back(View v) {
		Privilege.this.finish();
	}

	@OnClick(R.id.relSetTariff)
	public void onReportTest(View view) {
		new ActionSheetDialog(Privilege.this)
				.builder()
				.setCancelable(true)
				.setCanceledOnTouchOutside(true)
//				.addSheetItem("免费", SheetItemColor.Gray,
//						new OnSheetItemClickListener() {
//							@Override
//							public void onClick(int which) {
//								tvMyTariff.setText("免费");
//								mlUser.setPrice(0);
//								mlUser.saveInBackground(new SaveCallback() {
//
//									@Override
//									public void done(AVException arg0) {
//										// TODO Auto-generated method stub
//										if (arg0 == null) {
//											ToolKits.toast(Privilege.this,
//													"设置成功");
//										}
//
//									}
//								});
//
//							}
//						})
				.addSheetItem("0.5元/分钟", SheetItemColor.Gray,
						new OnSheetItemClickListener() {
							@Override
							public void onClick(int which) {
								tvMyTariff.setText("0.5元/分钟");
								mlUser.setPrice(0.5);
								mlUser.saveInBackground(new SaveCallback() {

									@Override
									public void done(AVException arg0) {
										// TODO Auto-generated method stub
										if (arg0 == null) {
											ToolKits.toast(Privilege.this,
													"设置成功");
											AVAnalytics.onEvent(Privilege.this, "特权资费设置");
										}

									}
								});
							}
						})
				.addSheetItem("1.0元/分钟", SheetItemColor.Gray,
						new OnSheetItemClickListener() {
							@Override
							public void onClick(int which) {
								tvMyTariff.setText("1元/分钟");
								mlUser.setPrice(1);
								mlUser.saveInBackground(new SaveCallback() {

									@Override
									public void done(AVException arg0) {
										// TODO Auto-generated method stub
										if (arg0 == null) {
											ToolKits.toast(Privilege.this,
													"设置成功");
											AVAnalytics.onEvent(Privilege.this, "特权资费设置");
										}

									}
								});

							}
							// })
							// .addSheetItem("2元/分钟", SheetItemColor.Gray,
							// new OnSheetItemClickListener() {
							// @Override
							// public void onClick(int which) {
							// tvMyTariff.setText("2元/分钟");
							// }
							// })
							// .addSheetItem("2.5元/分钟", SheetItemColor.Gray,
							// new OnSheetItemClickListener() {
							// @Override
							// public void onClick(int which) {
							// tvMyTariff.setText("2.5元/分钟");
							// }
							// })
							// .addSheetItem("3元/分钟", SheetItemColor.Gray,
							// new OnSheetItemClickListener() {
							// @Override
							// public void onClick(int which) {
							// tvMyTariff.setText("3元/分钟");
							// }
						}).show();
	}

	@OnClick(R.id.relHowToBe)
	public void onHowToBe(View view) {
		Intent intent = new Intent(Privilege.this, WebViews.class);
		intent.putExtra("url", "http://www.pocketsweet.com/howtobe");
		intent.putExtra("title", "如何成为虚拟恋人");
		startActivity(intent);
	}
	
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
	}

	@Override
	protected void onRestoreInstanceState(Bundle savedInstanceState) {
		super.onRestoreInstanceState(savedInstanceState);
	}

}
